using NUnit.Framework;

using Castle.ActiveRecord;
using Castle.ActiveRecord.Framework;
using Castle.ActiveRecord.Framework.Config;

namespace Pampa.CRUD.Test
{
    [TestFixture]
    public abstract class AbstractTestCase
    {
        protected SessionScope scope;

        [SetUp]
        public virtual void Init()
        {
            XmlConfigurationSource source = new XmlConfigurationSource("../../activerecord.xml");
            System.Reflection.Assembly asm = System.Reflection.Assembly.Load("Demo.Model");
            ActiveRecordStarter.Initialize(asm, source);

            PrepareSchema();
            CreateScope();
        }

        [TearDown]
        public virtual void Terminate()
        {
            DisposeScope();
            DropSchema();
        }

        [TestFixtureTearDown]
        public virtual void TerminateAll()
        {
        }

        protected void FlushAndRecreateScope()
        {
            DisposeScope();
            CreateScope();
        }

        protected void CreateScope()
        {
            scope = new SessionScope();
        }

        protected void DisposeScope()
        {
            scope.Dispose();
        }

        protected virtual void PrepareSchema()
        {
            ActiveRecordStarter.CreateSchema();
        }

        protected virtual void DropSchema()
        {
            ActiveRecordStarter.DropSchema();
        }
    }
}